const user = require("../sql/user");
const sql = require("../sql/index");
module.exports = function () {
    return (req, res, next) => {
        var a = req.query.id;
        var s = a.split('?')[0]
        // console.log(req.query.id)
        if (req.session.userid === s) {
            sql.get(user, { userid: s }, data => {
                // 改了
                if (data.length > 0) {
                    res.send(JSON.stringify({
                        code: 0,
                        msg: "获取成功,成功进入",
                        data: data[0]
                    }));
                } else {
                    res.send(JSON.stringify({
                        code: 1,
                        msg: "用户信息不存在,跳转到登录"
                    }));
                }
            })
        } else {
            res.send(JSON.stringify({
                code: 0,
                msg: "登录信息失效,重新登录",
            }));
        }
    }
}